package com.zzy.face.dao;

import com.zzy.face.dto.StudentInfo;
import com.zzy.face.dto.TeacherInfo;
import com.zzy.face.model.RLSchool;
import com.zzy.face.model.Student;
import com.zzy.face.model.Teacher;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author 朱泽玉
 * @Create 2022/1/29 11:05
 * @Description
 * @Modified By:
 */
@Repository
public interface StudentDao extends JpaRepository<Student, Long>, JpaSpecificationExecutor<Student> {
    @Query("SELECT new com.zzy.face.dto.StudentInfo(a.uid,a.Identity,a.birthday,a.college,a.date_time,a.idNumber,a.mobile,a.name,a.sex,s.major,s.uClass,a.state) from Account as a left join Student as s on a.uid = s.uid where s.uid is not null ")
    List<StudentInfo> findStudentsInfo();

    @Query("SELECT new com.zzy.face.dto.StudentInfo(a.uid,a.Identity,a.birthday,a.college,a.date_time,a.idNumber,a.mobile,a.name,a.sex,s.major,s.uClass,a.state) from Account as a left join Student as s on a.uid = s.uid and a.uid = ?1 where s.uid is not null ")
    StudentInfo findStudentInfo(Long uid);

    @Query("SELECT new com.zzy.face.dto.StudentInfo(a.uid,a.Identity,a.birthday,a.college,a.date_time,a.idNumber,a.mobile,a.name,a.sex,s.major,s.uClass,a.state) from Account as a left join Student as s on a.uid = s.uid and s.teacherId = ?1 where s.uid is not null ")
    List<StudentInfo> findStudentInfosInTeacher(Long teacherId);


//    @Query(value = "SELECT * from teacher where teacher_uid = ?1",nativeQuery = true)
//    Teacher findMyTeacher(Long student_uid);
}
